﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Windows.Forms;
using BusinessLogic.Connectivity.Entities;
using BusinessLogic.Connectivity.Interfaces;


namespace UserInterface.ClientApplication
{
	public partial class LoginForm : Form
	{
		public LoginForm()
		{
			InitializeComponent();
		}

		private void ExitButton_Click(object sender, EventArgs e)
		{
			if (
					MessageBox.Show(this, "Вы действительно хотите выйти?", "Выход...", MessageBoxButtons.YesNo,
									MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
			{
				Close();
			}
		}

		private void LoginButton_Click(object sender, EventArgs e)
		{
			if (LoginTextBox.Text != "")
			{
				string Login = LoginTextBox.Text;
				string Password = PasswordTextBox.Text;
				FormManager fm = new FormManager();
				new ExceptionCatcher().Execute(() =>
				                               {
				                               	fm.ValidateUser(Login, Password);
				                               	MainForm main_form = new MainForm();

				                               	fm.Login = Login;
				                               	fm.Password = Password;
				                               	fm.LoadState();
												Hide();
				                               	main_form.Show(fm);
				                               
				                               });




			}


		}



		private void LoginTextBox_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Return)
				PasswordTextBox.Focus();
		}

		private void PasswordTextBox_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Return)
				LoginButton_Click(sender, null);
		}

		private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			
		}
	}





}

